<template>
  <view>
    <view v-if="shareParams.visible" class="share-box" @tap="proxy.$refs.shareRef.open()">
      <view class="iconfont icon-fenxiang">
        <!-- <uni-icons type="contact" size="25"></uni-icons> -->
      </view>
      <view class="share"> 分享 </view>
    </view>

    <uni-popup ref="shareRef" type="bottom" border-radius="10px 10px 0 0">
      <view class="comp-share-box">
        <view class="title">
          {{ shareParams.title }}
          <uni-icons
            type="closeempty"
            size="20"
            color="#AFACA7"
            class="close-icon"
            @tap="proxy.$refs.shareRef.close()"
          ></uni-icons>
        </view>
        <!-- <image mode="heightFix" src="../../assets/templatea.png"></image> -->
        <view class="artistic-text">
          {{ shareParams.title }}
        </view>
        <view class="share">
          <button @tap="handleShare" class="btn" open-type="share">发送给好友</button>
        </view>
      </view>
    </uni-popup>
  </view>
</template>
<script setup lang="ts">
const { proxy } = getCurrentInstance();
const userInfoStore = useUserInfoStore();
const props = defineProps({
  templateId: {
    type: Number,
    default: null
  },
  shareParams: {
    type: Object,
    default: () => {
      return {
        templateId: "",
        visible: false,
        title: "分享标题",
        path: "/pages/templateDetail/index?type=123",
        summary: "分享描述",
        content: ""
      };
    }
  }
});

const handleShare = () => {
  uni.showShareMenu({
    withShareTicket: true,
    menus: ["shareAppMessage", "shareTimeline"]
  });
};

function addCount() {
  let shareParams = {
    templateId: props.templateId,
    userId: null,
    type: 3
  };
}

onShareAppMessage(() => {
  console.log("分享？？？？？？？>>>>1");
  proxy.$refs.shareRef.close();
  addCount();
  return {
    title: props.shareParams.title,
    path: props.shareParams.path,
    summary: props.shareParams.summary
  };
});

// 自定义页面的分享到朋友圈
onShareTimeline(() => {
  const { title, path } = props.shareParams || {};
  console.log(path, "onShareTimeline");

  return {
    title,
    path,
    summary: "分享描述"
  };
});
</script>
<style lang="scss" scoped src="./index.scss"></style>
